package com.cl.erp_2301.controller;

import com.cl.erp_2301.dto.DataDTO;
import com.cl.erp_2301.dto.GoodsDTO;
import com.cl.erp_2301.entity.Goods;
import com.cl.erp_2301.entity.GoodsType;
import com.cl.erp_2301.Service.GoodsService;
import com.cl.erp_2301.util.Result;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/v2")
public class GoodsController {
    @Resource
    private GoodsService goodsService;
    @GetMapping("/goods/listByPage")
    public Result listByPage(int page, int rows) {
        Page<Object> marketPage = PageHelper.startPage(page, rows);
        List<GoodsDTO> goodsDTOList=goodsService.listByPage();
        DataDTO data = new DataDTO();
        data.setRows(goodsDTOList);
        data.setTotal(marketPage.getTotal());
        return Result.ok(data);
    }
    @ResponseBody
    @RequestMapping( "/goods/goodstypelist" )
    public Result goodstypelist(){
        return Result.ok();
    }
    @ResponseBody
    @PostMapping(value = "/goods/add")
    public Result add(@RequestParam("name") String name){
        GoodsDTO goodsDTO=new GoodsDTO();
        goodsDTO.setName(name);
        goodsService.add(goodsDTO);
        return Result.ok();
    }
    @ResponseBody
    @PostMapping(value = "//goods/update")
    public Result update(@RequestParam("name") String name){
        GoodsDTO goodsDTO=new GoodsDTO();
        goodsDTO.setName(name);
        goodsService.update(goodsDTO);

        return Result.ok();
    }

}
